package com.scvtc.service.party;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scvtc.domain.ResResult;
import com.scvtc.domain.entity.party.PartyStudy;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.mapper.party.PartyStudyMapper;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service("PartyStudyService")
public class PartyStudyServiceImpl extends ServiceImpl<PartyStudyMapper, PartyStudy> implements PartyStudyService {

    @Override
    public ResResult<PageVo<List<PartyStudy>>> getAllInfo(Long current, Long size, PartyStudy partyStudy) {
        Page<PartyStudy> page= getBaseMapper().getAllInfo(new Page<PartyStudy>(current, size));
        return ResResult.noMsgSuccess(new PageVo<>(page.getRecords(), page.getTotal()));
    }

    @Override
    public ResResult<?> addOneStudy(PartyStudy partyStudy) {
        if (save(partyStudy)){
            return ResResult.success(partyStudy.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> updateStudy(PartyStudy partyStudy) {
        if (updateById(partyStudy)){
            return ResResult.success(partyStudy.getId());
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteStudy(Long id) {
        if (removeById(id)){
            return ResResult.success();
        }
        return ResResult.fail();
    }

    @Override
    public ResResult<?> deleteMultipleStudy(Long[] ids) {
        if (removeByIds(Arrays.asList(ids))){
            return ResResult.success();
        }
        return ResResult.fail();
    }
}
